from pymongo import MongoClient
import string
# import re
# from snownlp import SnowNLP

# open('l.txt', mode='r', encoding='UTF8').writelines('## %s\n\n' %'{:04}'.format(i))

queue = ''
lastqueue = ''                                                      # 去重
repl = string.punctuation+'“”、，。 《》°'         # !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~

for line in open('l.txt', mode='r', encoding='UTF8') :
    
    if line.startswith('##') :
        queue = queue.translate(str.maketrans('','', repl))
        if not ( queue.isspace() or queue == '' ) :
            if queue[:5] == lastqueue[:5] : queue = '' ; continue   # 去重
            lastqueue = queue                                       # 去重
            
            print(queue[:-1])

            # ans = input('? ans>')

            MongoClient()['db']['5-19'].insert_one({'Q':queue[:-1], 'A':ans})
            # MongoClient()['db']['temp'].insert_one( {'l2': '%s' %queue[:2], 'l4': '%s' %queue[:4], 'bk':'%s' %queue[queue.find('《') : queue.find('》')], 'ans':'%s' %ans} )
            
        queue = ''
        continue

    queue = queue+line[:-1]


